<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>用户权限控制管理</title>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 70px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">用户名</div>
                    <div class="field">
                        <input name="passiveCtrlUsrNm" id="passiveCtrlUsrNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">真实姓名</div>
                    <div class="field">
                        <input name="passiveCtrlRlNm" id="passiveCtrlRlNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">所属事业部</div>
                    <div class="field">
                        <input name="buOrgCd" id="buOrgCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">添加人</div>
                    <div class="field">
                        <input name="cstUsrNm" id="cstUsrNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">添加时间</div>
                    <div class="field">
                        <input ligerui="width:82" name="crtTmMin" id="crtTmMin" type="text" class="ui-datepicker" value="">-
                        <input ligerui="width:82" name="crtTmMax" id="crtTmMax" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">控制内容</div>
                    <div class="field">
                        <input name="ctrlContent" id="ctrlContent" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">控制原因</div>
                    <div class="field">
                        <input name="ctrlReason" id="ctrlReason" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">是否生效</div>
                    <div class="field">
                        <input name="isValid" id="isValid" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>

                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <span id="addBtn" class="sq-button sq-button-round" onclick="flowAuthAddBtnEvent();">新增</span>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/flowauth/prjFlowAuthCtrl/initList.do',
            method: 'get',
            columns: [
                /*用户名、真实姓名、所属机构、省公司、分公司、控制内容、控制项目类型、
                控制时间、控制结束时间、创建时间、添加人、添加原因、是否生效、操作*/
                {display: '用户名', name: 'passiveCtrlUsrNm', minWidth: 100, align: 'center', enabledSort: false },
                {display: '真实姓名', name: 'passiveCtrlRlNm', minWidth: 100, align: 'center', enabledSort: false,
                    render: function (rowdata, rowindex, value, column) {
                        if (StringUtils.isEmpty(value)) {
                            value = "";
                        }
                        var h = '';
                        h = '<a href="javascript:flowAuthDetail(';
                        h += "'" + rowdata.id + "'";
                        h += ')">' + value + '</a>'
                        return h;
                    }},
                {display: '所属机构', name: 'buOrgCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '省公司', name: 'prOrgCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '分公司', name: 'cyOrgCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '控制内容', name: 'ctrlContentNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '控制项目类型', name: 'ctrlPrjTypCdNm', minWidth: 100, align: 'left', enabledSort: false,},
                {display: '控制时间', name: 'ctrlStartDt', minWidth: 100, align: 'center', enabledSort: false,render: renderDate},
                {display: '控制结束时间', name: 'ctrlEndDt', minWidth: 100, align: 'center', enabledSort: false,render: renderDate},
                {display: '创建时间', name: 'crtTm', minWidth: 100, align: 'center', enabledSort: false,render: renderDate},
                {display: '添加人', name: 'crtUsrNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '是否生效', name: 'isValidNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '操作', name: '', minWidth: 100, align: 'left', enabledSort: false,
                    render:function (rowdata,rowindex,value) {
                        var cz = '';
                        if (rowdata.isShowModifyBtn == 1) {
                            cz += '<a onclick="flowAuthModifyBtnEvent('+rowdata.id+');"><i class="sqBtnIco_3"></i>修改</a>';
                        }
                        if (rowdata.isValidNm == '是') {
                            cz += ' | <a onclick="modifySts('+rowdata.id+');"><i class="sqBtnIco_3"></i>禁用</a>';
                        }
                        return  cz;
                    }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: false,
            allowUnSelectRow: true,
            alternatingRow: true,
        });
        grid.setHeight(100);

        $("#buOrgCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
        });
        $("#ctrlContent").ligerComboBox({
            valueField: 'key',
            textField: 'value',
        });
        $("#ctrlReason").ligerComboBox({
            valueField: 'key',
            textField: 'value',
        });
        $("#isValid").ligerComboBox({
            valueField: 'key',
            textField: 'value',
        });

        liger.get("buOrgCd").setData(${orgList});
        liger.get("ctrlContent").setData(${ctrlContentList});
        liger.get("ctrlReason").setData(${ctrlReasonList});
        liger.get("isValid").setData(${ynList});

        $("#searchBar").ligerForm();
        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        var callback = function () {
            grid.reload();
        };

    });

    //新增用户权限控制
    function flowAuthAddBtnEvent() {
        dialogForAddMain = $.ligerDialog.SQopen({
            width: 800,
            height: 420,
            _data: {openDialogForChooseUsr: openDialogForChooseUsr},
            title: '新增',
            url: '<%=path%>/flowauth/prjFlowAuthCtrl/toAddPage.do',
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
                    if (Dialog.onOk) Dialog.onOk();
                }
            }, {
                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }],
            onLoaded: function () {
                _subWin=dialogForAddMain.get("_subWin");
            }
        });
    };

    //选择人的Dialog
    function openDialogForChooseUsr () {
        var _usrs;
        if (dialogForAddMain.get("_usrs")!=undefined) {
            _usrs = encodeURI(JSON.stringify(dialogForAddMain.get("_usrs")));
        } else {
            _usrs = '';
        }
        dialogForChooseUsr = $.ligerDialog.SQopen({
            url: "<%=path%>/flowauth/prjFlowAuthCtrl/toChooseUsr.do?isMore=1&_users=" + _usrs,
            width: 1000,
            title: "选择组织用户",
            onClosed: function () {
                dialogForAddMain.show();
                var usrs=dialogForChooseUsr.get("_usrs");
                set_selected_usrs(usrs);
            },
            onHideDialog: function () {
                dialogForChooseUsr.close();
            }
        });
        dialogForAddMain.hide();
    }


    //弹出人员窗口设置人员
    function set_selected_usrs (usrs) {
        if (!usrs) return;
        dialogForAddMain.set("_usrs", usrs);
        var usrs_names=[];
        var usrs_ids=[];
        var usrs_orgCds=[];
        var usrs_orgCdNms=[];
        for (var i = 0; i < usrs.length; i++) {
            for(key in usrs[i]){
                usrs_names.push(usrs[i][key].rlNm);
                usrs_ids.push(key);
                usrs_orgCds.push(usrs[i][key].orgCd);
                usrs_orgCdNms.push(usrs[i][key].orgCdNm);
            }
        };
        _subWin.$("#passiveCtrlRlNm").val(usrs_names);
        _subWin.$("#passiveCtrlId").val(usrs_ids);
        _subWin.$("#passiveCtrlOrgCd").val(usrs_orgCds);
        _subWin.$("#passiveCtrlOrgCdNm").val(usrs_orgCdNms);
    }

    //修改用户权限控制
    function flowAuthModifyBtnEvent(_id) {
        if (!_id) {
            UIUtils.alertWarning(LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO);
            return; //验证不通过，不执行以下代码
        }
        $.ligerDialog.SQopen({
            width: 800,
            height: 420,
            title: '修改',
            url: '<%=path%>/flowauth/prjFlowAuthCtrl/toModifyPage.do?id=' + _id + '&editFlag=2',
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
                    if (Dialog.onOk) Dialog.onOk();
                }
            }, {
                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }]
        });
    }

    //被控制人详情
    function flowAuthDetail(_id) {
        if (!_id) {
            UIUtils.alertWarning(LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO);
            return; //验证不通过，不执行以下代码
        }
        $.ligerDialog.SQopen({
            width: 800,
            height: 420,
            title: '被控制人详情',
            url: '<%=path%>/flowauth/prjFlowAuthCtrl/toModifyPage.do?id=' + _id + '&editFlag=3',
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }]
        });
    }

    //禁用
    function modifySts(id){
        if(!id)return;
        $.ligerDialog.confirm(LogUtils.LOG_CMM_DISABLE_CONFIRM, function (flag) {
            if(flag == false)return;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType:'json',
                data: {
                    id: id,
                    isValid: 0
                },
                url: '<%=path%>/flowauth/prjFlowAuthCtrl/modifySts.do',
                beforeSend: function(){
                    wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING,SQ_type:"waitting"});
                },
                success:function(msg){
                    wait_dialog.close();
                    if(msg.success == 1){
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                        grid.reload();
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }
</script>
</body>
</html>
